package com.tron.sync.controller;

import com.alibaba.fastjson.JSON;
import com.tron.sync.entities.Wfinfoindex;
import com.tron.sync.syncwfinfoindex.PlatformClient;
import com.tron.sync.syncwfinfoindex.SyncWfInfoIndex;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "wfinfoindex")
@RestController
@RequestMapping("/wfinfoindex")
public class SyncWfInfoIndexController {
    @Autowired
    private SyncWfInfoIndex syncWfInfoIndex;

    @Autowired
    private PlatformClient platformClient;


    @ApiOperation(value = "根据机构id查询全文检索数据，并把用户信息保存到表中")
    @GetMapping("/getWfInfoData")
    public String getWfInfoData(@RequestParam("orgId") String orgId, @RequestHeader("token") String token){
        Wfinfoindex wfinfoindex = syncWfInfoIndex.getWfinfoindex(orgId, token);
        return "";
    }

    @ApiOperation(value = "根据机构id获取全文检索异常数据")
    @GetMapping("/queryAllElkData")
    public Object queryAllElkData(@RequestParam("orgId") String orgId, @RequestHeader("token") String token) {
        final List<Wfinfoindex> wfinfoindices = syncWfInfoIndex.queryListElkData(orgId, token);
        return wfinfoindices;
    }

    @ApiOperation(value = "根据全文检索id刷新数据")
    @GetMapping("/syncElkDateById")
    public Object syncElkDateById(@RequestParam("id") String id, @RequestHeader("token") String token) {
        final Map map = syncWfInfoIndex.updateElkDataById(id, token);
        return map;
    }

    @ApiOperation(value = "根据机构id更新全文检索异常数据")
    @GetMapping("/updateElkErrorData")
    public Object updateElkErrorData( @RequestHeader("token") String token) {
        return syncWfInfoIndex.updateElkErrorData(token);
    }

    @ApiOperation(value = "verifyOrgUser")
    @GetMapping("/verifyOrgUser")
    public Object verifyOrgUser(@RequestParam("orgId") String orgId, @RequestHeader("token") String token) {
        return platformClient.queryOrgUserRelation(JSON.parseObject("{\"parameters\":[{\"key\":\"orgId\",\"value\":\"" + orgId + "\"},{\"key\":\"hassub\",\"value\":\"0\"},{\"key\":\"roleId\",\"value\":\"\"}],\"requestPage\":{\"pageNo\":1,\"limit\":2000,\"totalCount\":3},\"sorts\":[]}"), token);
    }

    @ApiOperation(value = "updateElkErrorDataByOrgId")
    @GetMapping("/updateElkErrorDataByOrgId")
    public Object updateElkErrorDataByOrgId(@RequestParam("orgId") String orgId, @RequestHeader("token") String token) {
        return syncWfInfoIndex.updateElkErrorDataByOrgId(orgId, token);
    }

    @ApiOperation(value = "updateElkErrorDataById")
    @GetMapping("/updateElkErrorDataById")
    public Object updateElkErrorDataById(@RequestParam("id") String id) {
        return syncWfInfoIndex.updateElkErrorDataById(id);
    }

}
